package worldinruin;

import java.util.ArrayList;
import java.util.Collections;

import worldinruin.core.IGame;
import worldinruin.core.ISoldier;
import worldinruin.core.imp.battle.Battle;
import worldinruin.core.imp.soldiers.Archer;
import worldinruin.core.imp.soldiers.Catapult;
import worldinruin.core.imp.soldiers.Cavalier;
import worldinruin.core.imp.soldiers.Swordsman;
import worldinruin.file.IFile;
import worldinruin.file.imp.File;
import worldinruin.gui.IGui;
import worldinruin.gui.imp.MainFrame;
import worldinruin.resources.IconMap;
import worldinruin.rules.IRules;
import worldinruin.rules.imp.Rules;

public class GameDataHandler implements IGameDataHandler {
	
	private static GameDataHandler instance;
	private ArrayList<ISoldier> soldierTypes;
	private IGame game;
	private IGui gui;
	private IRules rules;
	private Battle battle;
	
	/**
	 * Single instance of GameDataHandler.
	 */
	private GameDataHandler() {
		soldierTypes = new ArrayList<ISoldier>();
		soldierTypes.add(new Archer());
		soldierTypes.add(new Catapult());
		soldierTypes.add(new Cavalier());
		soldierTypes.add(new Swordsman());
		
		Collections.sort(soldierTypes);
		
		rules = Rules.getInstance();
	}
	
	@Override
	public IGui getGui() {
		if(gui == null){
			gui = MainFrame.getInstance();
		}
		return gui;
	}
	
	@Override
	public IGame getGame(){
		return game;
	}
	
	@Override
	public IFile getFile(){
		return File.getInstance();
	}
	
	@Override
	public void setGame(IGame game){
		this.game = game;
	}
	
	@Override
	public IRules getRules(){
		return rules;
	}
	
	@Override
	public ArrayList<ISoldier> getSoldierTypes(){
		return soldierTypes;
	}
	
	/**
	 * Creates a single object of class.
	 * @return Single instance.
	 */
	public static GameDataHandler getInstance(){
		if(instance == null){
			instance = new GameDataHandler();
		}		
		return instance;
	}
	
	@Override
	public IconMap getIconMap() {
		return IconMap.getInstance();
	}
	
	@Override
	public void setBattle(Battle battle) {
		this.battle = battle;
	}
	
	@Override
	public Battle getBattle() {
		return battle;
	}
	
}